﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class UserWork_NewPassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (CompareValidator1.IsValid == true)
        {
            if (this.TextBox1.Text.Trim() == "" || this.TextBox2.Text.Trim() == "")
            {
                Response.Write("<script>alert('请填写正确资料')</script>");
            }
            else
            {
                SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
                con.Open();
                string sql = "update userinfo set Password='"+this.TextBox2.Text+"' where password='"+this.TextBox1.Text+"' and username='"+Session["UserName"].ToString()+"'";
                SqlCommand com = new SqlCommand(sql,con);
                if (com.ExecuteNonQuery() > 0)
                {
                    Response.Write("<script>alert('修改成功！');window.location.href='../Main.aspx';</script>");

                }
                else
                {
                    Response.Write("<script>alert('请填写正确资料')</script>");
                }
            
                con.Close();
            }
        }
        else
        {
            Response.Write("<script>alert('请填写正确资料')</script>");
        }
    }
}
